<?php 
include('conexion.php');

$fechade		 = $_POST['fechade'];
$fechaa 		 = $_POST['fechaa'];
$text_check 	 = $_POST['text_check'];

if($text_check == '1')
{
$consulta = mysql_query("SELECT protesto.id_protesto,protesto.solicitante,protesto.num_protesto,protesto.numero ,DATE_FORMAT(protesto.fec_ingreso,'%d/%m/%Y') AS 'fec_ingreso2' 
,IF(DATE_FORMAT(protesto.fec_notificacion,'%d/%m/%Y')='00/00/0000','',DATE_FORMAT(protesto.fec_notificacion,'%d/%m/%Y')) AS 'fec_notificacion2',
DATE_FORMAT(protesto.fec_constancia,'%d/%m/%Y') AS 'fec_constancia2',monedas.desmon,protesto.importe
FROM protesto
LEFT OUTER JOIN monedas ON monedas.idmon = protesto.moneda
WHERE protesto.fec_constancia BETWEEN STR_TO_DATE('$fechade','%d/%m/%Y') AND STR_TO_DATE('$fechaa','%d/%m/%Y')
ORDER BY protesto.id_protesto DESC", $conn) or die(mysql_error());
}
else if($text_check == '2')
{
$consulta = mysql_query("SELECT protesto.id_protesto,protesto.solicitante,protesto.num_protesto,protesto.numero ,DATE_FORMAT(protesto.fec_ingreso,'%d/%m/%Y') AS 'fec_ingreso2' 
,IF(DATE_FORMAT(protesto.fec_notificacion,'%d/%m/%Y')='00/00/0000','',DATE_FORMAT(protesto.fec_notificacion,'%d/%m/%Y')) 'fec_notificacion2',
DATE_FORMAT(protesto.fec_constancia,'%d/%m/%Y') AS 'fec_constancia2',monedas.desmon,protesto.importe
FROM protesto
LEFT OUTER JOIN monedas ON monedas.idmon = protesto.moneda
WHERE protesto.fec_notificacion BETWEEN STR_TO_DATE('$fechade','%d/%m/%Y') AND STR_TO_DATE('$fechaa','%d/%m/%Y')
ORDER BY protesto.id_protesto DESC", $conn) or die(mysql_error());		
}
else if($text_check == '3')
{
$consulta = mysql_query("SELECT protesto.id_protesto,protesto.solicitante,protesto.num_protesto,protesto.numero ,DATE_FORMAT(protesto.fec_ingreso,'%d/%m/%Y') AS 'fec_ingreso2' 
,IF(DATE_FORMAT(protesto.fec_notificacion,'%d/%m/%Y')='00/00/0000','',DATE_FORMAT(protesto.fec_notificacion,'%d/%m/%Y'))   AS 'fec_notificacion2',
DATE_FORMAT(protesto.fec_constancia,'%d/%m/%Y') AS 'fec_constancia2',monedas.desmon,protesto.importe
FROM protesto
LEFT OUTER JOIN monedas ON monedas.idmon = protesto.moneda
WHERE protesto.fec_ingreso BETWEEN STR_TO_DATE('$fechade','%d/%m/%Y') AND STR_TO_DATE('$fechaa','%d/%m/%Y')
ORDER BY protesto.id_protesto DESC", $conn) or die(mysql_error());		
}

while($rowkar = mysql_fetch_array($consulta)){

$numkar = $rowkar['num_protesto'];
$numkar2 = substr($numkar,5,6).'-'.substr($numkar,0,4);

$idprotesto = $rowkar['id_protesto'];
$feci = $rowkar['fec_ingreso2'];
$fecn = $rowkar['fec_notificacion2'];
$solicitante = strtoupper($rowkar['solicitante']);

echo"<table width='834' border='1' cellpadding='0' cellspacing='0' bordercolor='#E5E5E5'>
  <tr>
    <td width='30' valign='top'><span class='Estilo12'>".$idprotesto."</span></td>
	<td width='60' valign='top'><span class='Estilo12'>".$numkar2."</span></td>
	<td width='60' valign='top'><span class='Estilo12'>".$feci."</span></td>
	<td width='60' valign='top'><span class='Estilo12'>".$fecn."</span></td>
	<td width='150' valign='top'><span class='Estilo12'>".$solicitante."</span></td>
	<td width='150' valign='top'><span class='Estilo12'>";
	
	$consulcont = mysql_query("SELECT * FROM protesto_participantes WHERE protesto_participantes.id_protesto='".$rowkar['id_protesto']."'", $conn) or die(mysql_error());
	while($rowcont = mysql_fetch_array($consulcont)){
		$cantidadc=$rowcont['tip_condi'];
		
	switch ($cantidadc) {
	case "001":
	$ncliente="ACREEDOR";
	break;
	case "002":
	$ncliente="DEUDOR";	
	break;
	case "003":
	$ncliente="AVAL";
	break;
	}

	echo  $ncliente.": ".$rowcont['descri_parti']."<br>";
	}
	echo"</span></td>
	<td width='60' valign='top'><span class='Estilo12'>".$rowkar['fec_constancia2']."</span></td>
    <td width='60' valign='top'><span class='Estilo12'>".$rowkar['desmon']."</span></td>
	<td width='60' valign='top'><span class='Estilo12'>".$rowkar['importe']."</span></td>
  </tr>
</table>";
}

?>